package com.donzell;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableScheduling;

import com.donzell.storage.StorageProperties;
import com.donzell.storage.StorageService;


/**
 * ---------------------------------------------------------------------------
 *
 * ---------------------------------------------------------------------------
 * <strong>copyright</strong>： ©版权所有 北京都在哪网讯科技有限公司成都分公司<br>
 * ----------------------------------------------------------------------------
 * @author: hewei
 * @time:2016/11/2 16:22
 * ---------------------------------------------------------------------------
 */
@SpringBootApplication
@EnableAutoConfiguration  //开启自动配置
@EnableScheduling
@EnableConfigurationProperties(StorageProperties.class)
public class WebApplication extends SpringBootServletInitializer{
	Logger logger = LoggerFactory.getLogger(WebApplication.class);
	
    @Override  
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {  
        return application.sources(WebApplication.class);  
    }
    
	/**
     * Main Start
     */
    public static void main(String[] args) {
        SpringApplication.run(WebApplication.class);
    }
    
    @Bean
	CommandLineRunner init(StorageService storageService) {
		return (args) -> {
			logger.info("CommandLineRunner开始执行===>"+storageService);
            storageService.deleteAll();
            storageService.init();
		};
	}
}
